import { buildOption } from '/@/utils/helper/designHelper';
import { getFormTemplate } from '/@/api/form/design';
import { FormTemplateModel } from '/@/api/form/design/model';
import { FormJson } from '/@/model/generator/codeGenerator';
export async function getSystemJson(formId: string) {
  try {
    const res = await getFormTemplate(formId);
    const model = JSON.parse(res.formJson) as FormTemplateModel;
    const formJson = model.formJson as unknown as FormJson;
    return res.formJson ? buildOption(formJson, false) : null;
  } catch (error) {
    return null;
  }
  // const file = importLocale(formId);
  // try {
  //   const result = await file;
  //   return result && result.formProps ? result.formProps : null;
  // } catch (error) {
  //   return null;
  // }
}

// function importLocale(locale: string) {
//   return import(`./../../views/dev/${locale}/components/config.ts`);
// }

export async function getCustomJson(formId: string) {
  try {
    const res = await getFormTemplate(formId);
    const model = JSON.parse(res.formJson) as FormTemplateModel;
    const formJson = model.formJson as unknown as FormJson;
    return res.formJson ? buildOption(formJson, false) : null;
  } catch (error) {
    return null;
  }
}
